package boot

import (
	"fmt"
	"log"

	"github.com/kataras/iris/v12"
	"github.com/spf13/viper"

	"beesoft.ink/application/media/app/helper/storage"
	baseModel "beesoft.ink/application/media/app/model/base"
	baseService "beesoft.ink/application/media/app/service/base"
	"beesoft.ink/application/media/router"

	_ "github.com/go-sql-driver/mysql"
)

func Init() {
	baseService.InitCodePath()

	baseService.LoadConfig()

	app := iris.New()

	basePath := storage.File.GetAppRootDir()
	if viper.GetString("server.environment") == "development" {
		basePath = baseModel.CodePath
	}
	fmt.Println(basePath)
	app.RegisterView(iris.HTML(basePath+"/resource/view", ".html")) // 注册视图模版

	// router.Middleware(app)
	router.Init(app)
	// app.Use(func(ctx fiber.Ctx) error {
	// 	return ctx.SendStatus(404)
	// })

	go func() {
		// InitWorkflow() // 初始化工作流
	}()

	log.Fatal(app.Listen(viper.GetString("server.address")))
}
